package com.ftg.product.login.controller;

import com.ftg.product.login.pojo.Admin;
import com.ftg.product.login.pojo.User;
import com.ftg.product.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/login")
public class LoginController {
    @Autowired
    LoginService loginservice;
    @PostMapping("/show")
    public Map<String,Object> show(@RequestBody Admin admin, HttpServletRequest request) {
        boolean asd =loginservice.show(admin);
        Map<String, Object> map = new HashMap<>();
        if(asd==true) {
            HttpSession session=request.getSession();
            session.setAttribute("admin",map);
            map.put("code","0");
            map.put("msg","success");
        }else{
            map.put("code","0");
            map.put("msg","fail");
        }
        return map;

    }
    @PostMapping("/showall")
    public Map<String,Object> showall(@RequestBody User user,HttpServletRequest request) {
        boolean asd =loginservice.showall(user);
        Map<String, Object> map1 = new HashMap<>();
        if(asd==true) {
            HttpSession session=request.getSession();
            session.setAttribute("user",map1);
            map1.put("code","0");
            map1.put("msg","success");
        }else{
            map1.put("code","0");
            map1.put("msg","fail");
        }
        return map1;

    }
}

